
function mon_ctdt($sohang)
{
    
songanh=document.getElementById("soluongnganh").value
if($sohang==0)
    somon=document.getElementById("soluongmon").value
      
var mang="";    
for(h=0;h<songanh;h++){
    nganh=document.getElementById("nganh"+h);
    if(nganh.checked){
        mang=mang+nganh.value+",";
    }
} 
    
var httpxml;
try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
		  try
	 		{
			 httpxml=new ActiveXObject("Msxml2.XMLHTTP");
			}
  			catch (e)
			{
    			try
      		{
      		httpxml=new ActiveXObject("Microsoft.XMLHTTP");
     		 }
    			catch (e)
      		{
      		alert("Your browser does not support AJAX!");
      		return false;
      		}
    		}
  }
function stateck() 
    {
        
    if(httpxml.readyState==4)
      {
        var myarray=eval(httpxml.responseText);
        // Before adding new we must remove previously loaded elements
        
        if($sohang!=0){
            k=document.getElementById("monhoc"+$sohang);
            for(j=k.options.length-1;j>=0;j--)
                {
                    k.remove(j);
                }        
                        
            for (i=0;i<myarray.length;i++)
                {
                var optn = document.createElement("OPTION");
                optn.value = myarray[i];
                i++;
                optn.text = myarray[i];
                k.options.add(optn);
                } 
        }else{
          
            for(g=0;g<somon;g++){
                khoa=document.getElementById("khoa"+g);
                if(!khoa.checked){                  
                    k=document.getElementById("monhoc"+g);
                    for(j=k.options.length-1;j>=0;j--)
                    {
                        k.remove(j);
                    }        
                }
            }
           for(g=0;g<somon;g++){
                khoa=document.getElementById("khoa"+g);
                if(!khoa.checked){  
                    k=document.getElementById("monhoc"+g);        
                    for (i=0;i<myarray.length;i++)
                    {
                    var optn = document.createElement("OPTION");
                    optn.value = myarray[i];
                    i++;
                    optn.text = myarray[i];
                    k.options.add(optn);
                    } 
                }
           }   
        }
      }
    }   
       
var url="daotao/mon_ctdt.php";
url=url+"?ma_nganh="+mang;
url=url+"&sid="+Math.random();

httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
//----------------------------------------------------------------------------------------------------------------------

